const http = require('http')
const Url = require('url')

class Express {
    constructor() {
        this.routers = []
    }
    get(path, fn) {
        this.routers.push({
            pathname: path,
            fn: fn
        })
    }
    listen(...args) {
        http.createServer((req, res) => {
            const { pathname } = Url.parse(req.url)
            for (let route of this.routers) {
                if (route.pathname === pathname) {
                    route.fn(req, res)
                    return
                }
            }
        }).listen(...args)
    }
}

module.exports = () => {
    return new Express()
}
